//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    url:''
    
  },
  onLoad: function (option) {
    var that = this;
    var user = wx.getStorageSync('user')
    var open_id = wx.getStorageSync('open_id')
    // aurl: 'http://tongji.yougou520.cn/wztt/detail/index.html'
    if(option.id){
      that.setData({
          url: 'https://tongji.yougou520.cn/wztt?u_id=' + user.user_id + '&openid=' + open_id+'&id=' + option.id
      })
    } else if (option.article_id){
      that.setData({
          url: 'https://tongji.yougou520.cn/wztt/detail/index.html?u_id=' + user.user_id + '&openid=' + open_id +'&article_id=' + option.article_id
      })
    }else{
      that.setData({
          url: 'https://tongji.yougou520.cn/wztt?u_id=' + user.user_id + '&openid=' + open_id
      })
    }
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  onShareAppMessage: function (res) {
    console.log(res.webViewUrl);
    if (res.webViewUrl.indexOf('user') != -1){
        console.log('不能转发');
        return;
    }
    var URL = res.webViewUrl.split('?')[1];
    var URL_data = URL.split('&');
    var urlData = {};
    URL_data.forEach(function (item, index) {
      urlData[item.split('=')[0]] = item.split('=')[1];
    });
    console.log(urlData);
    var optdata = '';;
    if (urlData.article_id){
        optdata = 'article_id=' + urlData.article_id + '&'
    } else if (urlData.id){
        optdata = 'id=' + urlData.id + '&'
    }
    var that = this;
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: that.data.title,
      path: '/pages/index/index?' + optdata,
      success: function (res) {
          console.log('转发成功');
      },
      fail: function (res) {
          console.log('转发失败');
      }
    }
  }

})
